export function invertColor(color: string) {
  // console.log('debug invert color func', color);
  switch (color) {
    case 'white':
      return 'black';
    case 'black':
      return 'white';
    default:
      break;
  }

  let r, g, b, a;

  if (color.indexOf('#') === 0) {
    // hex format
    color = color.slice(1);

    if (color.length === 3) {
      r = parseInt(color[0] + color[0], 16);
      g = parseInt(color[1] + color[1], 16);
      b = parseInt(color[2] + color[2], 16);
      a = 1;
    } else if (color.length === 4) {
      r = parseInt(color[0] + color[0], 16);
      g = parseInt(color[1] + color[1], 16);
      b = parseInt(color[2] + color[2], 16);
      a = parseInt(color[3] + color[3], 16) / 255;
    } else if (color.length === 6) {
      r = parseInt(color.slice(0, 2), 16);
      g = parseInt(color.slice(2, 4), 16);
      b = parseInt(color.slice(4, 6), 16);
      a = 1;
    } else if (color.length === 8) {
      r = parseInt(color.slice(0, 2), 16);
      g = parseInt(color.slice(2, 4), 16);
      b = parseInt(color.slice(4, 6), 16);
      a = parseInt(color.slice(6, 8), 16) / 255;
    } else {
      throw new Error('Invalid hex color.');
    }
  } else if (color.indexOf('rgb') === 0) {
    // rgba? format
    const parts = color
      .slice(color.indexOf('(') + 1, color.indexOf(')'))
      .split(',');
    r = parseInt(parts[0]);
    g = parseInt(parts[1]);
    b = parseInt(parts[2]);
    a = parts[3] ? parseFloat(parts[3]) : 1.0;
  } else {
    throw new Error('Not Supported Yet!');
  }

  // invert color components
  const retVal = `rgba(${255 - r}, ${255 - g}, ${255 - b}, ${a.toFixed(2)})`;

  // console.log('debug invert color func to', retVal);
  return retVal;
}
